package com.it.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.product.comtroller.ProductUnitController;
import com.it.product.domain.ProductUnit;
import com.it.product.mapper.ProductUnitMapper;
import com.it.product.service.IProductUnitService;
import com.spzx.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * projectName: spzx-parent
 *
 * @author: 王宝贵
 * time: 2024/9/19 23:01 周四
 * description:
 */
@Service
public class ProductUnitServiceImpl   extends ServiceImpl<ProductUnitMapper, ProductUnit> implements IProductUnitService {

    @Autowired
    ProductUnitMapper productUnitMapper;

    /**
     * 分页查询商品单位
     * @param productUnit 查询条件
     * @return
     */
    @Override
    public IPage selectProductUnitPage(IPage<ProductUnit> productUnitPage, ProductUnit productUnit) {
        LambdaQueryWrapper<ProductUnit> queryWrapper =new LambdaQueryWrapper<>();

        //非空判断 条件只有一个name
        if(StringUtils.hasText(productUnit.getName())){
            queryWrapper.like(ProductUnit::getName,productUnit.getName());
        }
        queryWrapper.select(ProductUnit::getName,ProductUnit::getCreateTime,ProductUnit::getId);
        return productUnitMapper.selectPage(productUnitPage,queryWrapper);
    }
}